<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="警方案件编号" prop="policeCaseId">
        <el-input
          v-model="queryParams.policeCaseId"
          placeholder="请输入警方案件编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="学号" prop="studentId">
        <el-input
          v-model="queryParams.studentId"
          placeholder="请输入学号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="学生姓名" prop="studentName">
        <el-input
          v-model="queryParams.studentName"
          placeholder="请输入学生姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="学生所在学院" prop="studentCollege">
        <el-input
          v-model="queryParams.studentCollege"
          placeholder="请输入学生所在学院"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="学生所在班级" prop="studentClassname">
        <el-input
          v-model="queryParams.studentClassname"
          placeholder="请输入学生所在班级"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="长联系方式" prop="longPhone">
        <el-input
          v-model="queryParams.longPhone"
          placeholder="请输入长联系方式"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="短联系方式" prop="shortPhone">
        <el-input
          v-model="queryParams.shortPhone"
          placeholder="请输入短联系方式"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="案件类别" prop="caseType">
        <el-select v-model="queryParams.caseType" placeholder="请选择案件类别" clearable size="small">
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
      <el-form-item label="报警时间" prop="caseFirstTime">
        <el-input
          v-model="queryParams.caseFirstTime"
          placeholder="请输入报警时间"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="修改时间" prop="caseReviseTime">
        <el-input
          v-model="queryParams.caseReviseTime"
          placeholder="请输入修改时间"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="公安处理负责人" prop="policeId">
        <el-input
          v-model="queryParams.policeId"
          placeholder="请输入公安处理负责人"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="公安处理负责人姓名" prop="policeName">
        <el-input
          v-model="queryParams.policeName"
          placeholder="请输入公安处理负责人姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="公安负责人所在单位" prop="policeUnity">
        <el-input
          v-model="queryParams.policeUnity"
          placeholder="请输入公安负责人所在单位"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否二级学院协助" prop="caseCollage">
        <el-input
          v-model="queryParams.caseCollage"
          placeholder="请输入是否二级学院协助"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="二级学院负责人" prop="collegeId">
        <el-input
          v-model="queryParams.collegeId"
          placeholder="请输入二级学院负责人"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="二级学院负责人姓名" prop="collegeName">
        <el-input
          v-model="queryParams.collegeName"
          placeholder="请输入二级学院负责人姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="二级学院负责人所在分院" prop="collegeUnity">
        <el-input
          v-model="queryParams.collegeUnity"
          placeholder="请输入二级学院负责人所在分院"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="处理状态" prop="caseStatus">
        <el-select v-model="queryParams.caseStatus" placeholder="请选择处理状态" clearable size="small">
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
      <el-form-item label="回访负责人" prop="caseReturnVisitId">
        <el-input
          v-model="queryParams.caseReturnVisitId"
          placeholder="请输入回访负责人"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="回访负责人姓名" prop="caseReturnVisitName">
        <el-input
          v-model="queryParams.caseReturnVisitName"
          placeholder="请输入回访负责人姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="回访负责人所在单位" prop="caseReturnVisitUnity">
        <el-input
          v-model="queryParams.caseReturnVisitUnity"
          placeholder="请输入回访负责人所在单位"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否回访" prop="caseReturnVisit">
        <el-input
          v-model="queryParams.caseReturnVisit"
          placeholder="请输入是否回访"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="回访时间" prop="caseReturnVisitTime">
        <el-input
          v-model="queryParams.caseReturnVisitTime"
          placeholder="请输入回访时间"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:caseinfo:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:caseinfo:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:caseinfo:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:caseinfo:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="caseinfoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="案件号" align="center" prop="caseId" />
      <el-table-column label="警方案件编号" align="center" prop="policeCaseId" />
      <el-table-column label="学号" align="center" prop="studentId" />
      <el-table-column label="学生姓名" align="center" prop="studentName" />
      <el-table-column label="学生所在学院" align="center" prop="studentCollege" />
      <el-table-column label="学生所在班级" align="center" prop="studentClassname" />
      <el-table-column label="长联系方式" align="center" prop="longPhone" />
      <el-table-column label="短联系方式" align="center" prop="shortPhone" />
      <el-table-column label="案件类别" align="center" prop="caseType" />
      <el-table-column label="描述内容" align="center" prop="caseContent" />
      <el-table-column label="报警时间" align="center" prop="caseFirstTime" />
      <el-table-column label="修改时间" align="center" prop="caseReviseTime" />
      <el-table-column label="公安处理负责人" align="center" prop="policeId" />
      <el-table-column label="公安处理负责人姓名" align="center" prop="policeName" />
      <el-table-column label="公安负责人所在单位" align="center" prop="policeUnity" />
      <el-table-column label="是否二级学院协助" align="center" prop="caseCollage" />
      <el-table-column label="二级学院负责人" align="center" prop="collegeId" />
      <el-table-column label="二级学院负责人姓名" align="center" prop="collegeName" />
      <el-table-column label="二级学院负责人所在分院" align="center" prop="collegeUnity" />
      <el-table-column label="处理状态" align="center" prop="caseStatus" />
      <el-table-column label="回访负责人" align="center" prop="caseReturnVisitId" />
      <el-table-column label="回访负责人姓名" align="center" prop="caseReturnVisitName" />
      <el-table-column label="回访负责人所在单位" align="center" prop="caseReturnVisitUnity" />
      <el-table-column label="是否回访" align="center" prop="caseReturnVisit" />
      <el-table-column label="回访内容" align="center" prop="caseReturnVisitContent" />
      <el-table-column label="回访时间" align="center" prop="caseReturnVisitTime" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:caseinfo:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:caseinfo:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改案件信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="警方案件编号" prop="policeCaseId">
          <el-input v-model="form.policeCaseId" placeholder="请输入警方案件编号" />
        </el-form-item>
        <el-form-item label="学号" prop="studentId">
          <el-input v-model="form.studentId" placeholder="请输入学号" />
        </el-form-item>
        <el-form-item label="学生姓名" prop="studentName">
          <el-input v-model="form.studentName" placeholder="请输入学生姓名" />
        </el-form-item>
        <el-form-item label="学生所在学院" prop="studentCollege">
          <el-input v-model="form.studentCollege" placeholder="请输入学生所在学院" />
        </el-form-item>
        <el-form-item label="学生所在班级" prop="studentClassname">
          <el-input v-model="form.studentClassname" placeholder="请输入学生所在班级" />
        </el-form-item>
        <el-form-item label="长联系方式" prop="longPhone">
          <el-input v-model="form.longPhone" placeholder="请输入长联系方式" />
        </el-form-item>
        <el-form-item label="短联系方式" prop="shortPhone">
          <el-input v-model="form.shortPhone" placeholder="请输入短联系方式" />
        </el-form-item>
        <el-form-item label="案件类别" prop="caseType">
          <el-select v-model="form.caseType" placeholder="请选择案件类别">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="描述内容">
          <editor v-model="form.caseContent" :min-height="192"/>
        </el-form-item>
        <el-form-item label="报警时间" prop="caseFirstTime">
          <el-input v-model="form.caseFirstTime" placeholder="请输入报警时间" />
        </el-form-item>
        <el-form-item label="修改时间" prop="caseReviseTime">
          <el-input v-model="form.caseReviseTime" placeholder="请输入修改时间" />
        </el-form-item>
        <el-form-item label="公安处理负责人" prop="policeId">
          <el-input v-model="form.policeId" placeholder="请输入公安处理负责人" />
        </el-form-item>
        <el-form-item label="公安处理负责人姓名" prop="policeName">
          <el-input v-model="form.policeName" placeholder="请输入公安处理负责人姓名" />
        </el-form-item>
        <el-form-item label="公安负责人所在单位" prop="policeUnity">
          <el-input v-model="form.policeUnity" placeholder="请输入公安负责人所在单位" />
        </el-form-item>
        <el-form-item label="是否二级学院协助" prop="caseCollage">
          <el-input v-model="form.caseCollage" placeholder="请输入是否二级学院协助" />
        </el-form-item>
        <el-form-item label="二级学院负责人" prop="collegeId">
          <el-input v-model="form.collegeId" placeholder="请输入二级学院负责人" />
        </el-form-item>
        <el-form-item label="二级学院负责人姓名" prop="collegeName">
          <el-input v-model="form.collegeName" placeholder="请输入二级学院负责人姓名" />
        </el-form-item>
        <el-form-item label="二级学院负责人所在分院" prop="collegeUnity">
          <el-input v-model="form.collegeUnity" placeholder="请输入二级学院负责人所在分院" />
        </el-form-item>
        <el-form-item label="处理状态">
          <el-radio-group v-model="form.caseStatus">
            <el-radio label="1">请选择字典生成</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="回访负责人" prop="caseReturnVisitId">
          <el-input v-model="form.caseReturnVisitId" placeholder="请输入回访负责人" />
        </el-form-item>
        <el-form-item label="回访负责人姓名" prop="caseReturnVisitName">
          <el-input v-model="form.caseReturnVisitName" placeholder="请输入回访负责人姓名" />
        </el-form-item>
        <el-form-item label="回访负责人所在单位" prop="caseReturnVisitUnity">
          <el-input v-model="form.caseReturnVisitUnity" placeholder="请输入回访负责人所在单位" />
        </el-form-item>
        <el-form-item label="是否回访" prop="caseReturnVisit">
          <el-input v-model="form.caseReturnVisit" placeholder="请输入是否回访" />
        </el-form-item>
        <el-form-item label="回访内容">
          <editor v-model="form.caseReturnVisitContent" :min-height="192"/>
        </el-form-item>
        <el-form-item label="回访时间" prop="caseReturnVisitTime">
          <el-input v-model="form.caseReturnVisitTime" placeholder="请输入回访时间" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listCaseinfo, getCaseinfo, delCaseinfo, addCaseinfo, updateCaseinfo, exportCaseinfo } from "@/api/system/caseinfo";
import Editor from '@/components/Editor';

export default {
  name: "Caseinfo",
  components: {
    Editor,
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 案件信息表格数据
      caseinfoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        policeCaseId: null,
        studentId: null,
        studentName: null,
        studentCollege: null,
        studentClassname: null,
        longPhone: null,
        shortPhone: null,
        caseType: null,
        caseContent: null,
        caseFirstTime: null,
        caseReviseTime: null,
        policeId: null,
        policeName: null,
        policeUnity: null,
        caseCollage: null,
        collegeId: null,
        collegeName: null,
        collegeUnity: null,
        caseStatus: null,
        caseReturnVisitId: null,
        caseReturnVisitName: null,
        caseReturnVisitUnity: null,
        caseReturnVisit: null,
        caseReturnVisitContent: null,
        caseReturnVisitTime: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        policeCaseId: [
          { required: true, message: "警方案件编号不能为空", trigger: "blur" }
        ],
        studentId: [
          { required: true, message: "学号不能为空", trigger: "blur" }
        ],
        studentName: [
          { required: true, message: "学生姓名不能为空", trigger: "blur" }
        ],
        studentCollege: [
          { required: true, message: "学生所在学院不能为空", trigger: "blur" }
        ],
        studentClassname: [
          { required: true, message: "学生所在班级不能为空", trigger: "blur" }
        ],
        longPhone: [
          { required: true, message: "长联系方式不能为空", trigger: "blur" }
        ],
        shortPhone: [
          { required: true, message: "短联系方式不能为空", trigger: "blur" }
        ],
        caseType: [
          { required: true, message: "案件类别不能为空", trigger: "change" }
        ],
        caseFirstTime: [
          { required: true, message: "报警时间不能为空", trigger: "blur" }
        ],
        caseReviseTime: [
          { required: true, message: "修改时间不能为空", trigger: "blur" }
        ],
        policeId: [
          { required: true, message: "公安处理负责人不能为空", trigger: "blur" }
        ],
        policeName: [
          { required: true, message: "公安处理负责人姓名不能为空", trigger: "blur" }
        ],
        policeUnity: [
          { required: true, message: "公安负责人所在单位不能为空", trigger: "blur" }
        ],
        caseCollage: [
          { required: true, message: "是否二级学院协助不能为空", trigger: "blur" }
        ],
        collegeId: [
          { required: true, message: "二级学院负责人不能为空", trigger: "blur" }
        ],
        collegeName: [
          { required: true, message: "二级学院负责人姓名不能为空", trigger: "blur" }
        ],
        collegeUnity: [
          { required: true, message: "二级学院负责人所在分院不能为空", trigger: "blur" }
        ],
        caseStatus: [
          { required: true, message: "处理状态不能为空", trigger: "blur" }
        ],
        caseReturnVisitId: [
          { required: true, message: "回访负责人不能为空", trigger: "blur" }
        ],
        caseReturnVisitName: [
          { required: true, message: "回访负责人姓名不能为空", trigger: "blur" }
        ],
        caseReturnVisitUnity: [
          { required: true, message: "回访负责人所在单位不能为空", trigger: "blur" }
        ],
        caseReturnVisit: [
          { required: true, message: "是否回访不能为空", trigger: "blur" }
        ],
        caseReturnVisitTime: [
          { required: true, message: "回访时间不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询案件信息列表 */
    getList() {
      this.loading = true;
      listCaseinfo(this.queryParams).then(response => {
        this.caseinfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        caseId: null,
        policeCaseId: null,
        studentId: null,
        studentName: null,
        studentCollege: null,
        studentClassname: null,
        longPhone: null,
        shortPhone: null,
        caseType: null,
        caseContent: null,
        caseFirstTime: null,
        caseReviseTime: null,
        policeId: null,
        policeName: null,
        policeUnity: null,
        caseCollage: null,
        collegeId: null,
        collegeName: null,
        collegeUnity: null,
        caseStatus: 0,
        caseReturnVisitId: null,
        caseReturnVisitName: null,
        caseReturnVisitUnity: null,
        caseReturnVisit: null,
        caseReturnVisitContent: null,
        caseReturnVisitTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.caseId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加案件信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const caseId = row.caseId || this.ids
      getCaseinfo(caseId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改案件信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.caseId != null) {
            updateCaseinfo(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addCaseinfo(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const caseIds = row.caseId || this.ids;
      this.$confirm('是否确认删除案件信息编号为"' + caseIds + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delCaseinfo(caseIds);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有案件信息数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportCaseinfo(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
    }
  }
};
</script>
